package com.yh.csx.crm.core.enums;

import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * PaymentDaysEnum class
 * 账期：01（无账期），02（7天），03（15天），04（30天），05（45天），06（60天），07（90天）
 * @author huyalin
 * @date 2019/2/21
 */
public enum PaymentDaysEnum {
    NOT("01", "无账期"),
    ONE_WEEK("02", "7天"),
    TWO_WEEK("03", "15天"),
    ONE_MONTH("04", "30天"),
    FORTY_FIVE_DAYS("05", "45天"),
    SIXTY_DAYS("06", "60天"),
    NINETY_DAYS("07", "90天");

    private String code;
    private String name;

    PaymentDaysEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    private static final Map<String, PaymentDaysEnum> valueLookup = new ConcurrentHashMap<>(values().length);
    static {
        for (PaymentDaysEnum type : EnumSet.allOf(PaymentDaysEnum.class)) {
            valueLookup.put(type.code, type);
        }
    }

    public static PaymentDaysEnum resolve(String code) {
        return (code != null ? valueLookup.get(code) : null);
    }

    public static String resolveName(String code) {
        PaymentDaysEnum days = resolve(code);
        return days == null ? "" : days.getName();
    }
}
